window.addEventListener('load', function () {
    //切换主题部分开始
	var theme = document.getElementById('theme');
	var body = document.body;
	var main = document.querySelector('.main');
	//判断当前主题状态
	var isDarkTheme = false;
	// 切换主题的函数
	function toggleTheme() {
    	if (isDarkTheme) {
        	// 切换到亮色主题
        	body.classList.remove('dark-theme');
        	body.classList.add('light-theme');
        	main.classList.remove('dark-theme');
        	main.classList.add('light-theme');
        	isDarkTheme = false;
    	} else {
        	// 切换到暗色主题
        	body.classList.remove('light-theme');
        	body.classList.add('dark-theme');
        	main.classList.remove('light-theme');
        	main.classList.add('dark-theme');
        	isDarkTheme = true;
    	}
	}		
	// 添加点击事件监听器
	theme.addEventListener('click', toggleTheme);
	//切换主题部分结束

    // 客服聊天功能开始
    const customerServiceLink = document.getElementById('customer-service');
    const chatbox = document.getElementById('chatbox');
    const chatboxClose = document.getElementById('chatbox-close');
    const chatboxMessages = document.getElementById('chatbox-messages');
    const chatboxInput = document.getElementById('chatbox-input');
    const chatboxSend = document.getElementById('chatbox-send');

    // 点击客服链接显示聊天框
    customerServiceLink.addEventListener('click', function (e) {
        e.preventDefault();
        chatbox.style.display = 'flex';
        // 自动回复
        addMessage('客服', '你好！');
    });

    // 关闭聊天框
    chatboxClose.addEventListener('click', function () {
        chatbox.style.display = 'none';
        chatboxMessages.innerHTML = ''; // 清空聊天框内容
    });

    // 发送消息
    chatboxSend.addEventListener('click', sendMessage);
    chatboxInput.addEventListener('keypress', function (e) {
        if (e.key === 'Enter') {
            sendMessage();
        }
    });

    function sendMessage() {
        const userInput = document.getElementById('chatbox-input');
        const message = userInput.value.trim();
        if (message) {
            addMessage('用户', message);
            userInput.value = '';
            // 添加 1 秒延迟后自动回复
            setTimeout(() => {
                addMessage('客服', '你好！有什么可以为你解答的');
            }, 1000);
        }
    }

    function addMessage(sender, text) {
        const messageElement = document.createElement('div');
        messageElement.textContent = `${sender}: ${text}`;
        chatboxMessages.appendChild(messageElement);
        chatboxMessages.scrollTop = chatboxMessages.scrollHeight;
    }
    // 客服聊天功能结束
});